// npm下载ejs
// npm i ejs
// 引入模块
const http = require("http");
const fs = require("fs");
const ejs = require("ejs");
// => 输出渲染后的 HTML 字符串
var template = fs.readFileSync(__dirname + "\\1-hello.ejs", "utf-8");

const server = http.createServer((req, res) => {
  // => 输出渲染后的 HTML 字符串
  var data = ejs.render(template, {
    title: "hello ejs",
    content: "<strong>big hello ejs</strong>",
  });
  res.setHeader("Content-Type", "text/html");
  res.statusCode = 200;
  res.end(data);
});
const hostname = "127.0.0.1";
const port = 4000;
server.listen(port, hostname, () => {
  console.log(`Server running is http://${hostname}:${port}/`);
});
